define(function(require, exports, module) {
	require('jquery');
	require('fancybox');
	require('easing');
	require('jcookie');

	$('.main_wrap').mouseover(function(event) {
		/* Act on the event */
		//console.log(event)
	});
	function resume_index(){
		console.log('start')
		this.init();
	};
	resume_index.prototype = {
		setHTML: function(name,data){
			var obj = {
				userInfo: $('<div class="userInfoForm"><div class="userInfoFormInner"><h2 class="tit txtC">个人资料</h2><div class="dis txtC">请完善您的个人信息，<br />他们会自动同步到您的简历上。</div><div class="form_wrap"><form name="form_userInfo" id="form_userInfo"><ul class="form_list cf"><li class="size1of2"><label class="left">中文名字</label><div class="input_text_wrap left"><input id="name_c" name="name_c" type="text" class="form_text" /></div></li><li class="size1of2"><label class="left">英文名字</label><div class="input_text_wrap left"><input id="name_e" name="name_e" type="text" class="form_text" /></div></li><li class="size1of2"><label class="left">性别</label><div class="input_text_wrap left"><div class="cos_radio left"><div class="cos_inner"><input id="sex_1" name="sex" value="male" type="radio" class="form_radio" /></div></div><span class="flw left">男</span><div class="cos_radio left"><div class="cos_inner"><input id="sex_2" name="sex" value="female" type="radio" class="form_radio" checked="checked" /></div></div><span class="flw left">女</span></div></li><li class="size1of2"><label class="left">户籍</label><div class="input_text_wrap left"><input id="census" name="census" type="text" class="form_text" /></div></li><li class="size1of2"><label class="left">出生日期</label><div class="input_text_wrap left"><input placeholder="1970/01/01" id="birth" name="birth" type="text" class="form_text" /></div></li><li class="size1of2"><label class="left">手机号码</label><div class="input_text_wrap left"><input id="mobile" name="mobile" type="text" class="form_text" /></div></li><li class="size1of2"><label class="left">邮箱地址</label><div class="input_text_wrap left"><input id="mail" name="mail" type="text" class="form_text" /></div></li></ul><div class="submit_bar"><input class="form_submit" name="userInfoSubmit" type="button" value="确定" /></div></form></div></div></div>'),
				education: $('<div class="userInfoForm educationForm"><div class="userInfoFormInner educationFormInner"><div class="tip_pop"><h2>小贴士</h2><div class="context"><p>这一板块HR给你的时间只有10秒…20秒不能更多！</p><p>所以少年少女们，简单写明学校和主修专业。校园活动挑高大上的写，活动名称、担任职务、活动效果这三样就够了。</p><p>像多次获得廉师傅绿茶再来一瓶奖励这种就真不用写了。</p></div></div><h2 class="tit txtC"><span class="txt">教育信息</span><span class="icon icon_tips"></span><span class="icon icon_tips_flw"></span></h2><div class="form_wrap"><form name="form_education" id="form_education"><div class="form_list_scroll"><div class="form_list_wrap"></div></div><div class="add_bar cf"><span class="right icon_add add_btn">添加教育信息</span></div><div class="submit_bar"><input class="form_submit" name="educationSubmit" type="button" value="确定" /></div></form></div></div></div>'),
				jobrecord: $('<div class="userInfoForm educationForm jobrecordForm"><div class="userInfoFormInner educationFormInner jobrecordForm_inner"><div class="tip_pop"><h2>小贴士</h2><div class="context"><p>你来到了HR一定会重点关注的板块。表紧张，按照下面的三段式来写：</p><p>公司名称<br />担任岗位<br />主要职责<br />三段句式:“负责了…”“参与了…”“获得了…”</p><p>就是这样So easy. 妈妈再也不用担心你写简历。</p><p>举例：<br />2010.4-2010.11<br />赫斯特广告有限公司上海分公司</p><p>订阅部实习生</p><p>主要负责时尚杂志天猫店首页网站的美化和修改工作，包括轮播图 、banner图等。另外还负责制作宣传展板，宣传DM单以及易拉宝等宣传制品，得到领导和同事的一致好评</p></div></div><h2 class="tit txtC"><span class="txt">工作经验</span><span class="icon icon_tips"></span><span class="icon icon_tips_flw"></span></h2><div class="form_wrap"><form name="form_education" id="form_education"><div class="form_list_scroll"><div class="form_list_wrap"></div></div><div class="add_bar cf"><span class="right icon_add add_btn">添加工作经验</span></div><div class="submit_bar"><input class="form_submit" name="educationSubmit" type="button" value="确定" /></div></form></div></div></div>')
			};
			for(var i in obj){
				this[i] = obj[i];
			};
		},
		jobrecordPost: function(){
			var sf = this;
			var html = sf.jobrecord;
			var item_index = 1;
			setItem('jobrecordItem',item_index);
			$.fancybox.open(html,{
				wrapCSS : 'own_skin form_skin',
				padding : 0,
				beforeLoad: function(){

				},
				afterShow: function(e){
					addEvents();
				},
				afterClose: function(){

				}
			});
			function addEvents(){
				var tip_bl = true;
				$(html).find('h2.tit .icon_tips').on('click',function(e){
					var tip_pop = $(html).find('.tip_pop');
						fancy_block = $(html),
						fancy_block_inner = $(html).find('.userInfoFormInner');
					var w = fancy_block.width(),
						ww = tip_pop.width();
					if(tip_bl){
						tip_bl = false;
						$(this).addClass('active');
						fancy_block_inner.width(w-40);
						fancy_block.width(w+ww);
						tip_pop.show();
						$.fancybox.toggle();
					}else{
						tip_bl = true;
						$(this).removeClass('active');
						fancy_block_inner.width('atuo');
						fancy_block.width(w-ww);
						tip_pop.hide();
						$.fancybox.toggle();
					}
					
				});
				$(html).find('.form_submit').on('click',function(e){
					formFn();
				});
				$(html).find('.add_btn').on('click',function(e){
					item_index++;
					setItem('jobrecordItem',item_index);
				});
			};
			function setItem(str,index){
				html.find('.form_list_wrap').html('');
				for(var i=0;i<index;i++){
					var list = $('<div class="form_list_div"><div class="form_tit cf"><h3 class="left"></h3></div><ul class="form_list cf"><li class="size1of2"><label class="left">公司名称</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">部门/职位</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">入职时间</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">离职时间</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of1"><label class="left">工作职责</label><div class="input_text_wrap left"><textarea class="form_culm form_textarea"></textarea></div></li></ul></div>');
					if(i>0){
						$('<span class="right icon_remove btn_remove">删除</span>').appendTo(list.find('.form_tit'));
						list.addClass('notop');
					};
					list.find('h3').text('工作经验'+(i+1));
					list.find('.form_culm').each(function(ind,itm){
						var s = str+'_'+i+'_'+ind;
						$(itm).attr({id:s,name:s});
					});
					list.appendTo(html.find('.form_list_wrap'));
					list.find('.btn_remove').on('click',function(){
						item_index--;
						setItem('educationItem',item_index);
					});
					setTimeout(function(){
						html.find('.form_list_scroll').jScrollPane();
					},100);
				};
			};
			function formFn(){
				var form = html.find('form'),
					arrRules = [$.testChinaName,$.testChinaName,$.testChinaName,$.testDate,$.intro]
					postData = {},
					passBl = true;
				
				$(form).find('li').each(function(index,item){
					var val = $(item).find('textarea').length ? $(item).find('textarea').text() : $.trim($(item).find('input').val()),
						name = $(item).find('textarea').length ? $(item).find('textarea').attr('name') : $(item).find('input').attr('name');
					postData[name] = val;
					var tests = true;
					if(arrRules[index]){
						tests = arrRules[index](val);
					};
					if(val===''){
						tests = false;
					};
					if(!tests){
						passBl = false;
						$(item).addClass('error');

					}else{
						$(item).removeClass('error');
					};
				});
				if(passBl){
					console.log('post');
				}else{
					console.log(postData);
				};
			};
		},
		educationPost: function(e){
			var sf = this;
			var html = sf.education;
			var item_index = 1;
			setItem('educationItem',item_index);
			$.fancybox.open(html,{
				wrapCSS : 'own_skin form_skin',
				padding : 0,
				beforeLoad: function(){

				},
				afterShow: function(e){
					addEvents();
				},
				afterClose: function(){

				}
			});
			function addEvents(){
				var tip_bl = true;
				$(html).find('h2.tit .icon_tips').on('click',function(e){
					var tip_pop = $(html).find('.tip_pop');
						fancy_block = $(html),
						fancy_block_inner = $(html).find('.userInfoFormInner');
					var w = fancy_block.width(),
						ww = tip_pop.width();

					if(tip_bl){
						tip_bl = false;
						$(this).addClass('active');
						fancy_block_inner.width(w-40);
						fancy_block.width(w+ww);
						tip_pop.show();
						$.fancybox.toggle();
					}else{
						tip_bl = true;
						$(this).removeClass('active');
						fancy_block_inner.width('atuo');
						fancy_block.width(w-ww);
						tip_pop.hide();
						$.fancybox.toggle();
					}
					
				});
				$(html).find('.form_submit').on('click',function(e){
					formFn();
				});
				$(html).find('.add_btn').on('click',function(e){
					item_index++;
					setItem('educationItem',item_index);
				});
			};
			function setItem(str,index){
				html.find('.form_list_wrap').html('');
				for(var i=0;i<index;i++){
					var list = $('<div class="form_list_div"><div class="form_tit cf"><h3 class="left"></h3></div><ul class="form_list cf"><li class="size1of2"><label class="left">毕业院校</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">学历/学位</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">系/专业</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of2"><label class="left">毕业日期</label><div class="input_text_wrap left"><input type="text" class="form_culm form_text" /></div></li><li class="size1of1"><label class="left">专业介绍</label><div class="input_text_wrap left"><textarea class="form_culm form_textarea"></textarea></div></li></ul></div>');
					if(i>0){
						$('<span class="right icon_remove btn_remove">删除</span>').appendTo(list.find('.form_tit'));
						list.addClass('notop');
					};
					list.find('h3').text('教育信息'+(i+1));
					list.find('.form_culm').each(function(ind,itm){
						var s = str+'_'+i+'_'+ind;
						$(itm).attr({id:s,name:s});
					});
					list.appendTo(html.find('.form_list_wrap'));
					list.find('.btn_remove').on('click',function(){
						item_index--;
						setItem('educationItem',item_index);
					});
					setTimeout(function(){
						html.find('.form_list_scroll').jScrollPane();
					},100);
				};
			};
			function formFn(){
				var form = html.find('form'),
					arrRules = [$.testChinaName,$.testChinaName,$.testChinaName,$.testDate,$.intro]
					postData = {},
					passBl = true;
				
				$(form).find('li').each(function(index,item){
					var val = $(item).find('textarea').length ? $(item).find('textarea').text() : $.trim($(item).find('input').val()),
						name = $(item).find('textarea').length ? $(item).find('textarea').attr('name') : $(item).find('input').attr('name');
					postData[name] = val;
					var tests = true;
					if(arrRules[index]){
						tests = arrRules[index](val);
					};
					if(val===''){
						tests = false;
					};
					if(!tests){
						passBl = false;
						$(item).addClass('error');

					}else{
						$(item).removeClass('error');
					};
				});
				if(passBl){
					console.log('post');
					sf.jobrecordPost();
				}else{
					console.log(postData);
					sf.jobrecordPost(); //暂时
				};
			};
		},
		userInfoPost: function(){
			var sf = this;
			var html = sf.userInfo;
			$.fancybox.open(html,{
				wrapCSS : 'own_skin form_skin',
				padding : 0,
				beforeLoad: function(){

				},
				afterShow: function(){
					addEvents();
				},
				afterClose: function(){

				}
			});
			function addEvents(){
				$(html).find('input:radio').on('click',function(e){
					e.stopPropagation();
				});
				$(html).find('.cos_radio').each(function(index,item){
					if($(item).find('input:radio').is(':checked')){
						$(this).addClass('checked');
					};
					$(item).on('click',function(){
						$(html).find('.cos_radio').removeClass('checked');
						$(this).addClass('checked').find('input:radio').click();
					});
				});
				$(html).find('.form_submit').on('click',function(e){
					formFn();
				});
			};
			function formFn(){
				var form = html.find('form'),
					arrRules = [$.testChinaName,null,null,$.testChinaName,$.testDate,$.testMobile,$.testMail],
					postData = {},
					passBl = true;
				$(form).find('li').each(function(index,item){
					var val = $(item).find('input:checked').length ? $(item).find('input:checked').val() : $.trim($(item).find('input').val());

					postData[$(item).find('input').attr('name')] = val;
					var tests = true;
					if(arrRules[index]){
						tests = arrRules[index](val);
					};
					if(val===''){
						tests = false;
					};
					if(!tests){
						passBl = false;
						$(item).addClass('error');

					}else{
						$(item).removeClass('error');
					};
				});
				if(passBl){
					console.log('post');
					sf.educationPost();
				}else{
					console.log(postData);
					sf.educationPost(); //暂时
				}
			};
		},
		init: function(){
			var sf = this;
			var userInfoData = true;
			this.setHTML();
			if(userInfoData){
				setTimeout(function(){
					sf.userInfoPost();
				},10);
			};
		}
	};
	var resume_index_emp;
	if($('#resume_index').length){
		resume_index_emp = new resume_index();
	};
	$('.resume_model_list li .resume_model_item a').each(function(index,item){ //简历魔板页事件
		var cover = $('<div class="item_cover"><div class="culm_black">就他了</div></div>');
		$(item).on('mouseenter',function(){
			cover.appendTo(item);
		});
		$(item).on('mouseleave',function(){
			cover.remove();
		});
		$(item).on('click',function(){//设置用户选择的简历模板，写入cookie和href
			$.cookie('_resume_model_index',index,{expires: 1});
			window.location.href = $(this).attr('href')+'?resume_model_index='+index;
			return false;
		});
	});
	$('.resume_control .navlist').each(function(index,item){
		$(item).find('.download .icon').on('click',function(){
			$(item).find('.flw').show();
		});
	});

	$()
});

